package com.ikas.ai.server.module.system.controller;

import com.ikas.ai.handle.JsonResult;
import com.ikas.ai.handle.JsonResultType;
import com.ikas.ai.server.config.EnvConfig;
import com.ikas.ai.utils.DateTimeUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/system")
@RefreshScope
public class IndexController {

    @Value("${app.version:1.0.0}")
    private String appVersion;

    @Value("${app.pe.model}")
    private String appModel;

    @RequestMapping("/info")
    public JsonResult getSysInfo(HttpServletRequest request, HttpServletResponse response) {
        JsonResult result = new JsonResult(JsonResultType.OK);
        result.add("title", EnvConfig.getTitle());
        result.add("titleEn", EnvConfig.getConfig("app.titleEn"));
        result.add("version", appVersion);
        result.add("appVersion", EnvConfig.getConfig("app.pe.version"));
        result.add("appModel", appModel);
        result.add("time", DateTimeUtil.getDateTimeString());
        return result;
    }

    @RequestMapping("/info2")
    public JsonResult info2(HttpServletRequest request, HttpServletResponse response) {
        return JsonResult.ok().setMessage("OK")
                .add("title", EnvConfig.getTitle())
                .add("titleEn", EnvConfig.getConfig("app.titleEn"))
                .add("version", appVersion)
                .add("appVersion", EnvConfig.getConfig("app.pe.version"))
                .add("appModel", appModel)
                .add("time", DateTimeUtil.getDateTimeString());
    }
}
